[#include "../../../common/html.ftl" /]
[@html]
    [@head title="字典数据列表" css=["fw", "bootstrap-table"] /]
    [@body]
        [#--主体内容--]
        [@main ]
            <div class="am-g am-radius fw-tables">
                [#--表格主体内容--操作栏--]
                [@mainHeader]
                    [#--[@shiro.hasPermission name="system:dictData:add"]--]
                    <button class="am-btn am-btn-success am-radius" onclick="add()">添加</button>
                    [#--[/@shiro.hasPermission]--]
                    [#--[@shiro.hasPermission name="system:dictData:remove"]--]
                    <button class="am-btn am-btn-danger am-radius multiple am-disabled" onclick="$.operate.removeAll()">删除</button>
                    [#--[/@shiro.hasPermission]--]
                [/@mainHeader]

                [#--表格主体内容--搜索栏--]
                [@searchForm searchId="form-data-search" ]
                    <div class="am-form-group">
                        <select id="dictType" name="dictType" class="am-radius" data-am-selected placeholder="字典名称">
                            <option value=""></option>
                            [#list typeList as dict]
                                [#if dict.dictType == type.dictType ]
                                    <option value="${dict.dictType}" selected>${dict.dictName}</option>
                                [#else]
                                    <option value="${dict.dictType}">${dict.dictName}</option>
                                [/#if]
                            [/#list]
                        </select>
                    </div>
                    <div class="am-form-group">
                        <input type="text" name="dictLabel" class="am-form-field am-input-sm am-radius" placeholder="字典标签">
                    </div>
                    <div class="am-form-group">
                        <select name="configType" class="am-radius" data-am-selected placeholder="数据状态">
                            <option value=""></option>
                            [#list dict.getType("sys_dict_status") as dict]
                                [#if dict.dictValue == type.status ]
                                    <option value="${dict.dictValue}" selected>${dict.dictLabel}</option>
                                [#else]
                                    <option value="${dict.dictValue}">${dict.dictLabel}</option>
                                [/#if]
                            [/#list]
                        </select>
                    </div>
                    <div class="am-form-group">
                        <select name="buildIn" class="am-radius" data-am-selected placeholder="是否内置字典">
                            <option value=""></option>
                            [#list dict.getType("sys_yes_no") as dict]
                                [#if dict.dictValue == type.buildIn ]
                                    <option value="${dict.dictValue}" selected>${dict.dictLabel}</option>
                                [#else]
                                    <option value="${dict.dictValue}">${dict.dictLabel}</option>
                                [/#if]
                            [/#list]
                        </select>
                    </div>
                [/@searchForm]

                <div class="fw-table">
                    <table id="bootstrap-table"></table>
                </div>
            </div>
        [/@main]

        [#--PC/APP 右侧悬浮按钮--]
        [@rightToolbar /]

        [@script js=["fw", "bootstrap-table"]]
            <script type="text/javascript">
                [#--var editFlag = "${hasPermission('system:dictData:edit')}";--]
                [#--var removeFlag = "${hasPermission('system:dictData:remove')}";--]
                var editFlag = "";
                var removeFlag ="";
                var datas = ${convert.toJson(dict.getType("sys_dict_status"))};
                var datasYesNo = ${convert.toJson(dict.getType("sys_yes_no"))};
                var isAdministrator = ${convert.toJson(common.isAdministrator())};

                var prefix = ctx + "osfw/system/dict/data";

                $(function () {
                    var options = {
                        url: prefix + "/list",
                        createUrl: prefix + "/add/{dictType}",
                        updateUrl: prefix + "/edit/{id}",
                        removeUrl: prefix + "/remove",
                        queryParams: queryParams,
                        sortName: "dictSort",
                        sortOrder: "asc",
                        modalName: "字典数据",
                        uniqueId: "dictCode",
                        columns: [
                            {
                                checkbox: true
                            },
                            {
                                title: "序号",
                                formatter: function (value, row, index) {
                                    return $.table.serialNumber(index);
                                }
                            },
                            {
                                field: 'dictLabel',
                                title: '字典标签',
                                formatter: function (value, row, index) {
                                    if ($.common.isNotEmpty(row.cssClass)) {
                                        return $.common.sprintf("<span class='am-badge am-radius' style='color:#fff; background-color: %s'>%s</span>", row.cssClass, row.dictLabel);
                                    }else {
                                        var listClass = $.common.equals("default", row.listClass) || $.common.isEmpty(row.listClass) ? "" : "am-badge am-badge-" + row.listClass + " am-radius";
                                        return $.common.sprintf("<span class='%s'>%s</span>", listClass, row.dictLabel);
                                    }
                                }
                            },
                            {
                                field: 'dictValue',
                                title: '字典键值'
                            },
                            {
                                field: 'dictSort',
                                title: '字典排序'
                            },
                            {
                                field: 'status',
                                title: '状态',
                                align: 'left',
                                formatter: function (value, row, index) {
                                    return $.table.selectDictLabel(datas, value);
                                }
                            },
                            {
                                visible: isAdministrator ? true : false,
                                switchable: isAdministrator ? true : false,
                                field: 'buildIn',
                                title: '系统内置',
                                formatter: function (value, row, index) {
                                    return $.table.selectDictLabel(datasYesNo, value);
                                }
                            },
                            {
                                visible: isAdministrator ? true : false,
                                title: '操作',
                                cellStyle: operCellStyle,
                                formatter: function (value, row, index) {
                                    var actions = [];
                                    actions.push('<a class="am-badge am-badge-transparent am-radius ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.editFull(\'' + row.dictCode + '\')">编辑</a> ');
                                    actions.push('<a class="am-badge am-badge-transparent am-radius ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.dictCode + '\')">删除</a>');
                                    return actions.join('');
                                }
                            }]
                    };
                    $.table.init(options);
                });

                function queryParams(params) {
                    var search = $.table.queryParams(params);
                    search.dictType = $("#dictType").val();
                    return search;
                }

                /*字典数据-添加字典*/
                function add() {
                    $.modal.openFull("添加" + table.options.modalName, table.options.createUrl.replace("{dictType}", $("#dictType").val()));
                }

                function resetPre() {
                    $.form.reset();
                    $("#dictType").val($("#dictType").val()).trigger("change");
                }

            </script>
        [/@script]
    [/@body]
[/@html]
